package com.project.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Title: TestServlet
 * @Package: com.project.servlet
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/6/20 - 16:45
 */
@SuppressWarnings("all")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        设置请求编码集，只对post有效
        req.setCharacterEncoding("utf-8");
//        设置响应信息的MIME运行和编码集
        resp.setContentType("text/html;charset=utf-8");
//        根据表单名，得到表单值
        String userName=req.getParameter("userName");
//        向客户端输出文本信息
        resp.getWriter().print("Tomcat Sysytem Test Pass/测试通过"+userName);
    }
}
